<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
<base href="<%=basePath%>">
  <meta charset="utf-8" />
  <link href="static/css/bootstrap.min.css" rel="stylesheet" />
  <script src='static/js/jquery-1.9.1.min.js'></script>
  <script  type="text/javascript" src="static/js/My97DatePicker/WdatePicker.js"></script>
  <script type="text/javascript">
  $(top.hangge());
  function reurl(){
      //UE.getEditor('content');
  }
  setTimeout('reurl()',500);

  $(document).ready(function(){
	  $.ajax({ 
		  type: "post",
		  url:"cuijiMessage/selectMessageNum.do",
		  success:function(data){
			  var res=data.result;
			$("#weiduBtn").val("未读消息("+res+")");
		}});

	  $("#weiduBtn").click(function(){
			//设置状态显示未读
			$("#status option[value='0']").attr("selected",true);
			//提交表单
			$("#form").submit();
	  });
  });
  function selectBtn(){
	  $("#form").submit();
  }
  function changeStatus(id){
	  //标记为已读
	  $.get("cuijiMessage/changeWeidu.do?id="+id,function(data){
		  //提交表单
		  $("#form").submit();
		  
	  })
	  //刷新页面
  }
  function deleteMsg(id,status){
	if(status==0){
		var r=window.confirm("确定删除该条未读信息吗？");
		if(r==true){
			 $.get("cuijiMessage/deleteMsg.do?id="+id,function(data){
				  //提交表单
				  $("#form").submit();
				  
			  })
		}else{
			return false;
		}
	}else{
		 $.get("cuijiMessage/deleteMsg.do?id="+id,function(data){
			  //提交表单
			  $("#form").submit();
			  
		  })
	}
  }
   function checkDate(){
	  var beginDate=$("#temp").val();
	  var endDate=$("#temp1").val();
	  var date1=new Date(beginDate.replace(/-/g,"\/"));
	  var date2=new Date(endDate.replace(/-/g,"\/"));
	   if(endDate!=''){
		   if(date1>date2) {
			   alert("开始时间不能大于结束时间！");
			   $("#temp1").val('');
			   return false;
		  }
	   }
  }


  </script>
</head>
<body>
<hr style ="height:1px;border:none;border-top:1px groove ghostwhite;">
<form action="cuijiMessage/tocuijiMessage.do" id="form" name="form" method="post">
	<div style="height:30px;width:100%;margin-left:20px">
		<div class="pull-left search "style="margin-left: 5px;">
    		<label >查询时间:</label>
  		</div>
  		<div class="pull-left search"   style="margin-left: 5px;">
  		 <input type="text" id="temp" name="temp" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" class="Wdate" style="width:300px" value="${pd.temp}"/>
  		 <input type="text" id="temp1" name="temp1" onblur="checkDate()" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" class="Wdate" style="width:300px" value="${pd.temp1}"/>
  		</div>
  		<div class="pull-left search "style="margin-left: 5px;">
    		<label >状态:</label>
  		</div>
  		<div class="pull-left search"   style="margin-left: 5px;">
    		<select id="status" name="status" "${pd.status}">
    			<option value=" ">不限</option>
    			<option value="0" <c:if test="${pd.status == '0' }">selected</c:if> >未读</option>
                <option value="1" <c:if test="${pd.status == '1' }">selected</c:if> >已读</option>
    		</select>
  		</div>
	</div>
	<br/>
	<div style="text-align:left" align="left" width="-30%">
 	 	<button id="chaxun" class="btn btn-primary" onclick="selectBtn()">查询</button>
	</div>
	<div style="text-align:right"align="right" width="30%">
   		&nbsp; &nbsp; &nbsp;
 	 	<input type="button" id="weiduBtn" name="weiduBtn" value=""/>
	</div>
</form>
<hr style ="height:1px;border:none;border-top:1px groove ghostwhite;">
<table class="table table-hover dataTable" border="1px" bordercolor="gainsboro" style="margin-left: 40px;" width="1450px">
  <thead>
  	<tr height="35px" align="center">
    <th width="5%" align="center">序号</th>
    <th width="6%">标题</th>
    <th width="8%">消息时间</th>
    <th width="8%">消息内容</th>
    <th width="7%">状态</th>
    <th width="10%">操作</th>
  </tr>
  </thead>
  <tbody>
  	<c:forEach var='pg' varStatus="vs" items="${page.pageList}">
  		<tr>
  			<td class='center' style="width: 30px;">${vs.index+1}</td>
  			<td>${pg.title}</td>
  			<td><fmt:formatDate value="${pg.create_time}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
  			<td>${pg.content}</td>
  			<td>
  				<c:if test="${pg.status==0}">未读</c:if>
  				<c:if test="${pg.status==1}">已读</c:if>
  			</td>
  			<td>
  				<div class='hidden-phone visible-desktop btn-group'>
  						<a class='btn btn-mini btn-info' title="删除" onclick="deleteMsg('${pg.id }',${pg.status});">删除</a>
  					<c:if test="${pg.status==0}">
  						<a class='btn btn-mini btn-info' title="标记为已读" onclick="changeStatus('${pg.id }');">标记为已读</a>
  					</c:if>&nbsp;
  				</div>
			</td>
  		</tr>
  	</c:forEach>
  </tbody>
  </table>
 <div class="page-header position-relative">
  <table style="width: 100%;">
    <tr>
      <td style="vertical-align: top;">
        <div class="pagination"
             style="float: right; padding-top: 0px; margin-top: 0px;">${page.pageStr}
        </div></td>
    </tr>
  </table>
</div>

</body>
</html>